<%-- 
    Document   : realEstateManagement
    Created on : Oct 26, 2011, 3:37:26 PM
    Author     : Group 106
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp"%>
<%@page import="java.util.ArrayList" %>
<%@page import="com.aptech.model.RealEstateStyle" %>
<%@page import="com.aptech.model.User" %>
<%@page import="com.aptech.model.PostHistory" %>
<%@page import="com.aptech.model.RealEstate" %>
<%@page import="com.aptech.DAO.realEstateStyleDAO" %>
<%@page import="com.aptech.DAO.postHistoryDAO" %>
<%@page import="com.aptech.DAO.realEstateDAO" %>

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <link rel="stylesheet" href="CSS/msh_style.css"/>
        <link rel="stylesheet" href="CSS/gallery_style.css"/>
        <link rel="stylesheet" href="CSS/css.css" />
       <!-- <link rel="stylesheet" href="CSS/css_header.css" />
         <link rel="stylesheet" href="CSS/css_footer.css" /> -->
        <link rel="stylesheet" href="CSS/mn_left.css" />
        <link rel="stylesheet" href="CSS/css_houseInfo.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <%
                User objUser = null;
                int userID;
                ArrayList<PostHistory> listPostHistory = new ArrayList<PostHistory>();
                ArrayList<RealEstate> listRealEstate = new ArrayList<RealEstate>();
                if (request.getSession().getAttribute("user") != null) {
                    postHistoryDAO objPostHistoryDAO = new postHistoryDAO();
                    objUser = (User) request.getSession().getAttribute("user");
                    userID = objUser.getUserID();
                    //response.sendRedirect("getPostHistoryByUserID.do?userID=" + userID);
                    listPostHistory = objPostHistoryDAO.getPostHistoryByUserID(userID);

    %>
    <body>
        <div id="wrap">
            <%@include file="header.jsp" %>   
            <div class="clear_with_heght"></div><!--End .clear-->
            <div id="main">
                <div id="left_sidebar">
                    <div id="houseType">
                        <div class="mn_header_left"></div>
                        <div class="mn_header_center">Bat Dong San</div>
                        <div class="mn_header_right"></div>

                        <div class="mn_content_left"></div>
                        <div class="mn_content_center">
                            <!--Code Here-->
				Selling house</div>
                        <div class="mn_content_right"></div>
                        <div class="mn_content_left"></div>
                        <div class="mn_content_center">Rental house</div>
                        <div class="mn_content_right"></div>

                        <div class="mn_content_left"></div>
                        <div class="mn_content_center">Paying house</div>
                        <div class="mn_content_right"></div>

                        <div class="mn_content_left"></div>
                        <div class="mn_content_center">All</div>
                        <div class="mn_content_right"></div>

                        <div class="mn_footer_left"></div>
                        <div class="mn_footer_content"></div>
                        <div class="mn_footer_right"></div>
                    </div><!--End #houseType-->
                    <div id="houseType">
                        <div class="mn_header_left"></div>
                        <div class="mn_header_center">Bat Dong San</div>
                        <div class="mn_header_right"></div>

                        <div class="mn_content_left"></div>
                        <div class="mn_content_center"></div>
                        <div class="mn_content_right"></div>

                        <div class="mn_footer_left"></div>
                        <div class="mn_footer_content"></div>
                        <div class="mn_footer_right"></div>
                    </div><!--End #houseType-->
                </div><!--End #left_sidebar-->
                <div id="content">
                    <%
                                        if (listPostHistory.size() > 0) {
                    %>
                    <div id="houseInfo">
                        <div id="mn_houseInfo_header_left"></div>
                        <div id="mn_houseInfo_header_center">House</div>
                        <div id="mn_houseInfo_header_right"></div>
                        <%
                        realEstateDAO   objRealEstateDAO = new realEstateDAO();
                           for (int i = 0; i < listPostHistory.size(); i++) {
                           PostHistory objPostHistory = listPostHistory.get(i);
                           int RealEstateID = objPostHistory.getRealEstateID();
                           listRealEstate = objRealEstateDAO.getRealEstateByID(RealEstateID);
                           for (int j = 0; j < listRealEstate.size(); j++) {
                           RealEstate objRealEstate = listRealEstate.get(j);
                        %>

                        <div class="mn_houseInfo_content_center">

                            <div class="houseImage"><%
                            out.print("<img src=\"Imgs/realEstate_Imgs/"
                            + objRealEstate.getImage() + "\" width=\"70\""
                            + " height=\"70\" />");
                                %>
                            </div>
                            <div class="houseDescription">
                                <%
                                   out.print(objRealEstate.getDescription() + "</a>");
                                %>
                            </div>
                            <div class="houseManagement">
                                <div id ="management">
                                    <a href="realEstateStyle.jsp">Dang Tin</a> | Sua Thong Tin | Huy Dang Tin |
                                    <a href="deleteRealEstate.do?realEstateID=<%=RealEstateID%>"onclick=" return confirm('Do you want delete ?')" > Delete</a></div>
                                <div id ="endDate">Han dang tin: 20/10/2011</div>
                                <div id ="startDate">Ngay dang tin: 20/09/2011 </div>
                            </div>
                        </div>

                        <% }
                                                                    }
                        %>
                        <div id="mn_houseInfo_footer_left"></div>
                        <div id="mn_houseInfo_footer_center"></div>
                        <div id="mn_houseInfo_footer_right"></div>
                    </div><!--End #houseInfo-->
                    <%                                            } else {
                                            out.print("<table width=\"100%\" align=\"center\" height=\"200\">"
                                                    + "<tr>"
                                                    + "<td align=\"center\">Ban Chua Dang Tin Ban Nha Nao! Click <strong> <a href=\"realEstateStyle.jsp?userID=" + userID + "\">vao day</a></strong> de dang tin</td>"
                                                    + "</tr></table>");
                                        }
                    %>
                </div><!--End #content-->
            </div><!--End #main-->
            <div class="clear"></div><!--End .clear-->
            <div id="msh_footer_panel" style=" width: 942px;">
    Copyright © 2011 <a href="aptech.vn">Ha Noi - Aptech</a> | <a href="home.jsp" target="_parent">Website My Sweet Home</a> by <a href="home.jsp" target="_blank">Group 106</a>
</div><!--End #footer-->
            <div class="clear"></div><!--End .clear-->
        </div><!--End #wrap-->
        <div class="clear"></div><!--End .clear-->
    </body>
    <%
                } else {
                    response.sendRedirect("login.jsp");
                }
    %>
</html>